package com.kaibes.platform.currency.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.kaibes.core.base.annotation.Description;
import com.kaibes.web.admin.AdminController;
import com.kaibes.module.user.UserService;
import com.kaibes.platform.currency.db.CurrencyExchangeService;
import com.kaibes.platform.currency.db.CurrencyService;
import com.kaibes.web.api.ApiLink;

@AdminController
@RequestMapping("/admin/currency")
public class CurrencyController {

    @Autowired
    private CurrencyService currencyService;
    @Autowired
    private CurrencyExchangeService currencyExchangeService;
    @Autowired
    private UserService userService;
    
    @GetMapping("type")
    @ApiLink("货币种类管理界面")
    public String currencyType(Model model) {
        model.addAttribute("currencyList", currencyService.list());
        return "currency-type";
    }
    
    @GetMapping("exchange")
    @ApiLink("货币兑换管理界面")
    public String currencyExchange(Model model) {
        model.addAttribute("currencyExchangeList", currencyExchangeService.list());
        model.addAttribute("currencyList", currencyService.list());
        return "currency-exchange";
    }
    
    @GetMapping("user")
    @ApiLink("用户货币管理界面")
    public String currencyUser(Model model, 
            @RequestParam(defaultValue = "25") @Description("每页数量") int size,
            @RequestParam(defaultValue = "1") @Description("页号") int page, 
            @RequestParam(defaultValue = "") @Description("搜索内容") String search) {
        search = search.trim();
        if (!search.isEmpty()) {
            model.addAttribute("userPage", userService.pageByNicknameLike(page, size, search));
        } else {
            model.addAttribute("userPage", userService.page(page, size));
        }
        model.addAttribute("currencyList", currencyService.list());
        return "currency-user";
    }
    
}
